package com.example.hotel_demo.mapper;

import com.example.hotel_demo.pojo.Customer;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
@Mapper
public interface CustomerMapper {
    /**
     * 住宿登记
     * <a href="">住宿登记</a>             <br>
     * -------------------
     * <a href="">顾客信息管理</a>
     * <a href="">添加顾客信息管理</a>   <a href="">删除顾客信息管理</a>   <a href="">修改顾客信息管理</a>   <br>
     *     String custName, String username, int custNum, int custPhone, String sex, int roomID, String custState
     */

    //顾客界面登记,1 有顾客信息，通过查询自己的证件号获得是否入住登记过，
    //          2 登记过，通过update方式填入username 3 未登记过，通过insert方式
    @Select("select * from Customer where custNum = #{custNum}")
    public Customer getCustByCustNum();

    @Select("select count(*) from Customer")
    public int getCustCount();

    @Select("select count(*) from Customer where custState = 1")
    public int getlivingCount();

    @Update("update Customer set username = #{username} where custNum=#{custNum}")
    public int updateCustByCustNum(String custNum,String username);

    @Insert("insert into Customer (custName,username,custNum,custPhone,sex,roomID, custState) values(#{custName},#{username},#{custNum},#{custPhone},#{sex},#{roomID},#{custState})")
    public int addCustByUser(String custName, String username, String custNum, int custPhone, String sex, int roomID, int custState);


    //管理员登记，可以没有username
    @Insert("insert into Customer (custName,custNum,custPhone,sex,roomID, custState) " +
            "values(#{custName},#{custNum},#{custPhone},#{sex},#{roomID},#{custState})")
    public int addCust(String custName, String custNum, int custPhone, String sex, int roomID, int custState);

    @Update("update Customer set username = #{username} where userID=#{userID}")
    public int updateCustUserNameByUserID(int userID,String username);

    @Select("select * from Customer ")
    public List<Customer> getCustAll();

    @Delete("delete from Customer where custID = #{custID}")
    public int deleteCustByCustID(int custID);

    @Update("update Customer set custName=#{custName},username=#{username},custNum=#{custNum},custPhone=#{custPhone},sex=#{sex},roomID=#{roomID} ,custState=#{custState}  where custID = #{custID}")
    public int updateCustNameByCustID(int custID,String custName, String username, String custNum, int custPhone, String sex, int roomID, int custState);

    @Select("select * from Customer where uID = #{uID}")
    Customer findByUID(int uID);

    @Insert("insert into Customer (custName,uID,custNum,custPhone,sex) values(#{custName},#{uID},#{custNum},#{custPhone},#{sex})")
    int addCustMsg(String custName, int uID, String custNum, String  custPhone, String sex);

    @Update("update customer set custName=#{custName},custNum=#{custNum},custPhone=#{custPhone},sex=#{sex}  where uID = #{uID}")
    int update(Customer customer);

    @Select("select custName from Customer where custNum = #{custNum}")
    public String getcustNameByNum(String custNum);

    @Select("select custPhone from Customer where custNum = #{custNum}")
    public int getcustPhoneByNum(String custNum);

    @Update("update customer set roomID=#{roomID},custState=#{custState}  where custNum = #{custNum2}")
    int updateCustState(String custNum2, String roomID, int custState);

    @Update("update customer set custState=#{custState}  where custNum = #{custNum}")
    void updateCustStateBy(String custNum, int custState);

    @Select("select * from Customer where uID = #{uid}")
    Customer getCustByUid(String uid);

    @Update("update customer set custName=#{custName} custNum=#{custNum} custPhone=#{custPhone} " +
            " sex=#{sex}  where custID = #{custID}")
    int updateCustByCustID(String custID, String custName, String custNum, String custPhone, String sex);

    @Update("update customer set uID = null where uID = #{uid}")
    int updateCustUidByuid(String uid);
}
